package com.hzp.lolnews.ui.novel.other;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;

/**
 * Created by Administrator on 10/24 0024.
 */
public class ShareListener {


    private static UMShareAPI mShareAPI;

    public static void shareListener(final Context context, final String content, final String title){
        //初始化
        mShareAPI = UMShareAPI.get(context);
        //第三方分享监听
        UMShareListener umShareListener = new UMShareListener() {
            @Override
            public void onResult(SHARE_MEDIA platform) {
                Log.d("plat", "platform" + platform);

                Toast.makeText(context, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onError(SHARE_MEDIA platform, Throwable t) {
                Toast.makeText(context, platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
                if (t != null) {
                    Log.d("throw", "throw:" + t.getMessage());
                }
            }

            @Override
            public void onCancel(SHARE_MEDIA platform) {
                Toast.makeText(context, platform + " 分享取消了", Toast.LENGTH_SHORT).show();
            }
        };
        //设置分享的平台
        SHARE_MEDIA[] list = new SHARE_MEDIA[]{
                SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.DOUBAN,
                SHARE_MEDIA.EMAIL, SHARE_MEDIA.SMS, SHARE_MEDIA.RENREN, SHARE_MEDIA.YNOTE
        };

        new ShareAction((Activity) context)
                .setDisplayList(list)//设置分享的平台列表
                .withText(content)//分享的内容
                .withTitle(title)//分享的标题
                //.withTargetUrl(url)//分享一个链接
                //.addButton()
                .setCallback(umShareListener)//分享的监听
                .open();//打开分享面板
    }
}
